public class test03 {
    public boolean isHappy(int n) {
        Set<Integer> hashset = new HashSet<>();
        while(!hashset.contains(n)){
            hashset.add(n);
            n = nextNumber(n);
        }
        return n==1;
    }
    private int nextNumber(int n){
        int res = 0;
        while(n>0){
            int tmp = n%10;
            res += tmp*tmp;
            n = n/10;
        }
        return res;
    }
}
